#ifndef USRAI_H
#define USRAI_H

#include "AI.h"
#include <functional>

extern tagGame tagUsrGame;
extern ins UsrIns;
/*##########DO NOT MODIFY THE CODE ABOVE##########*/

class UsrAI:public AI
{
public:
    UsrAI(){this->id=0;}
    ~UsrAI(){}
    void farmerAction();
    void assignHuttingTask();
    void fishingFish();
    void createFarmer();
    void createSailing();
    void createBoat();
    void createShip();
    void createClubman();
    void createScout();
    void createBowman();
    void createSlinger();
    void destroyShip();
    void destroyFish();
    void updateScience();
    void assignBoardTask(vector<tagFarmer> &landFarmer,vector<int> &boardFarmer,int farmerNumber);
    void exploreOcean(tagHuman & human);
    void assignOceanTask();
    void assignTransportTask();
    void assignEnemyLandTask();
    void initFarmer();
    void init();
    void assignFishingTask();
    void exploreEnermyLand(tagHuman& human);
    void assignBuildTask(int BUILDING_TYPE,vector<tagFarmer>& idleFarmer,vector<tagFarmer>& workingFarmer,int workingNum,function<pair<int,int>()> func,int BUILDING_RESOURCE,int buildingNum=1);
    void assignResourceTask(int RESOURCE_TYPE,vector<tagFarmer>& idleFarmer,vector<tagFarmer>& workingFarmer,int workingNum,bool enemyFlag);
private:
    void processData() override;
    tagInfo getInfo(){return tagUsrGame.getInfo();}
    int AddToIns(instruction ins) override
    {
        UsrIns.lock.lock();
        ins.id=UsrIns.g_id;
        UsrIns.g_id++;
        UsrIns.instructions.push(ins);
        UsrIns.lock.unlock();
        return ins.id;
    }
    void clearInsRet() override
    {
        tagUsrGame.clearInsRet();
    }
    /*##########DO NOT MODIFY THE CODE IN THE CLASS##########*/
    bool tryBuildBuilding(int buildingType, int requiredWood, int maxCount, int reqiredBuilding,int is_settler=0);
    //
};

/*##########YOUR CODE BEGINS HERE##########*/
void initMap();
void initArmy();
void findNearestResource();
bool isEnermyLand(int DR, int UR);
bool isPreBuild(int);
bool isNearCenter(int,int);
bool isCoast(int,int);
bool isValidCoordinate(int x, int y);
int getAroundLand(int,int);
int gerAroundOcean(int,int);
int getNumberEnermyCoast();
pair<int,int> findBoardPos();
/*##########YOUR CODE ENDS HERE##########*/
#endif // USRAI_H
